import XLSX from 'xlsx';

export default {
    read(file) {
        return new Promise((resolve, reject) => {
            const reader = new FileReader();
            reader.readAsBinaryString(file);
            reader.onload = (e) => {
                try {
                    const wb = XLSX.read(e.target.result, {type: 'binary'});
                    const data = [];
                    wb.SheetNames.forEach(name => {
                        data[name] = XLSX.utils.sheet_to_json(wb.Sheets[name], {header: 1})
                    });
                    resolve(data);
                } catch (e) {
                    reject('解析文件出错,请检查您所选择的文件是否是在当前页面下载的模板文件,请勿自行修改sheet名称,如仍未能解决问题，请联系我们');
                }
            };
        });
    }
}